<?php 
defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
	
	$idc=intval($_REQUEST['idc']);
	$id=intval($_REQUEST['id']);
	$filter=intval($_GET['filter']);
	
if(!$id){
	$tpl = new TemplatePower("template/products.htm");
			$tpl->prepare();		
			$tpl->assignGlobal("site_address",$site_address);
			$tpl->assignGlobal("pathpage1",Get_Main_CatPD_Name_path($idc));
			
			$sql="SELECT * FROM catpd WHERE active=1 AND parentid=$idc ORDER BY thu_tu DESC, name ASC";
			$db=$DB->query($sql);
			if(mysql_num_rows($db)>0){
				while($rs=mysql_fetch_array($db)){
					$tpl->newBlock("new_cell")	;
					$tpl->assign("name",$rs['name']);
					$tpl->assign("link_detail",$site_address.$rs['url']);
					if(file_exists($CONFIG['upload_image_path'].$rs['small_image'])){	
						$size=@getimagesize($CONFIG['upload_image_path'].$rs['small_image']);
						if($size[0]>$size[1]){
							$tpl->assign("image","<img width='167' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0'>");
						}else{
							$tpl->assign("image","<img height='142' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0' class='borderimage_product_list'>");
						}
					}
				}
			}else{
			
				$sql1="SELECT * FROM product WHERE active=1 AND id_catpd IN(".Get_Id_CatPD($idc).") ORDER BY thu_tu DESC, name ASC";				
				$db1=phan_trang_rewrite($_GET['p'],$site_address.get_url_product($idc),$sql1,8,12);
				while($rs1=mysql_fetch_array($db1['db']))	{
					$tpl->newBlock('new_cell');				
					$tpl->assign("name",$rs1['name']);
					if(file_exists($CONFIG['upload_image_path'].$rs1['small_image'])){	
						$size=@getimagesize($CONFIG['upload_image_path'].$rs1['small_image']);
						if($size[0]>$size[1]){
							$tpl->assign("image","<img width='167' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0'>");
						}else{
							$tpl->assign("image","<img height='142' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0' class='borderimage_product_list'>");
						}
					}
					$tpl->assign("link_detail",$site_address.get_url_product($rs1['id_catpd']).clean_url($rs1['name'])."_".$rs1['id_product'].'.html');
				}			
				$tpl->assignGlobal("pages",$db1['cac_trang']);
			}
	
	$tpl->printToScreen();	
}
if($id){
	$tpl = new TemplatePower("template/productdetail.htm");
	$tpl->prepare();		
	$tpl->assignGlobal("site_address",$site_address);
	$tpl->assignGlobal("pathpage1",Get_Main_CatPD_Name_path($idc));
	
	$sql="SELECT * FROM product WHERE active=1 AND id_product=$id";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$tpl->assign("name",$rs['name']);
		

	
		$tpl->assign("name",$rs['name']);
		$tpl->assign("content",$rs['content']);
		if(check_showfix($rs['id_catpd'])==true){
			$tpl->assign("khac","Khác");
			$tpl->newBlock("showinfofix");
			$tpl->assign("chatlieu",$rs['chatlieu']);
			$tpl->assign("kichthuoc",$rs['kichthuoc']);
			$tpl->assign("congngheson",$rs['congngheson']);
			$tpl->assign("khayo",$rs['khayo']);
			$tpl->assign("lammat",$rs['lammat']);
			$tpl->assign("nguon",$rs['nguon']);
			$tpl->assign("conggiaotiep",$rs['conggiaotiep']);
		}else{
			$tpl->assign("khac","Chi tiết");	
		}
		
		
		
		if(file_exists($CONFIG['upload_image_path'].$rs['normal_image']) && $rs['normal_image']){	
			$size=@getimagesize($CONFIG['upload_image_path'].$rs['normal_image']);
			if($size[0]>=$size[1]){
				$tpl->assign("image_product_detail","<img alt='".clean_url($rs['name'])."' width='200' src='".$site_address.$CONFIG['upload_image_path'].$rs['normal_image']."' border='0' >");
			}else{
				$tpl->assign("image_product_detail","<img alt='".clean_url($rs['name'])."' height='200' src='".$site_address.$CONFIG['upload_image_path'].$rs['normal_image']."' border='0' >");
			}
		}else if(file_exists($CONFIG['upload_image_path'].$rs['small_image']) && $rs['normal_image']){	
			$size=@getimagesize($CONFIG['upload_image_path'].$rs['small_image']);
			if($size[0]>=$size[1]){
				$tpl->assignGlobal("image_product_detail","<img width='200' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0' >");
			}else{
				$tpl->assignGlobal("image_product_detail","<img height='200' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0' >");
			}
		}
		$tpl->assign("bigimage1",$site_address.$CONFIG['upload_image_path'].$rs['image']);
		
	}
	// orther image
	$sql1="SELECT * FROM image_product WHERE id_product=$id ORDER BY name ASC";
	$db1=$DB->query($sql1);
	$i=0;
	while($rs=mysql_fetch_array($db1)){
		$tpl->newBlock("show_other");
		$i++;
		if(file_exists($CONFIG['upload_image_path'].$rs['normal_image']) && $rs['normal_image']){	
			$size=getimagesize($CONFIG['upload_image_path'].$rs['normal_image']);
			if($size[0]>=$size[1]){
				$tpl->assign("image","<img alt='".clean_url($rs['name'])."' width='230' src='".$site_address.$CONFIG['upload_image_path'].$rs['normal_image']."' border='0' >");
			}else{
				$tpl->assign("image","<img alt='".clean_url($rs['name'])."' height='210' src='".$site_address.$CONFIG['upload_image_path'].$rs['normal_image']."' border='0' >");
			}
		}else if(file_exists($CONFIG['upload_image_path'].$rs['small_image']) && $rs['normal_image']){	
			$size=@getimagesize($CONFIG['upload_image_path'].$rs['small_image']);
			if($size[0]>=$size[1]){
				$tpl->assignGlobal("image","<img width='230' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0' >");
			}else{
				$tpl->assignGlobal("image","<img height='210' alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' border='0' >");
			}
		}
		$tpl->assign("bigimage",$site_address.$CONFIG['upload_image_path'].$rs['image']);
		if($i%3==0) $tpl->assign("br","</tr><tr>"); 
	}
	
	
	$sql1="SELECT * FROM product WHERE active=1 AND id_catpd IN(".Get_Id_CatPD($idc).") AND id_product<>$id ORDER BY thu_tu DESC, name ASC";				
			
	$db1=phan_trang_rewrite($_GET['p'],$site_address.get_url_product($idc),$sql1,8,8);

	while($rs1=mysql_fetch_array($db1['db']))	{
		$tpl->newBlock('new_cell');				
		$tpl->assign("name",$rs1['name']);
		if(file_exists($CONFIG['upload_image_path'].$rs1['small_image'])){	
			$size=getimagesize($CONFIG['upload_image_path'].$rs1['small_image']);
			if($size[0]>$size[1]){
				$tpl->assign("image","<img width='167' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0'>");
			}else{
				$tpl->assign("image","<img height='142' alt='".clean_url($rs1['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs1['small_image']."' border='0' class='borderimage_product_list'>");
			}
		}
		$tpl->assign("link_detail",$site_address.get_url_product($rs1['id_catpd']).clean_url($rs1['name'])."_".$rs1['id_product'].'.html');
	}	
	
	$tpl->printToScreen();	
}

function check_showfix($idc){
	global $DB;
	$sql="SELECT * FROM catpd WHERE id_catpd=$idc";
	$db=$DB->query($sql);
	$kt=false;
	if($rs=mysql_fetch_array($db)){
		if($rs['showinfofix']==1) return false;
		else return true;
	}
}

?>